package cn.buk.tms.eotms.util;

import jakarta.validation.constraints.NotNull;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yfdai
 */
public class FlightTicketUtil {

    /**
     * 校验单张机票票号的正确性
     * 校验票号是否为14位或13位
     * @param ticketNo
     * @return
     */
    public static boolean verifyTicketNo(@NotNull String ticketNo) {
        if (ticketNo == null) {
            return false;
        }
        String regEx = "[0-9]{3}-?[0-9]{10}";

        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(ticketNo);

        return m.matches();
    }

    /**
     * 校验联程机票
     * @param ticketNo
     * @return
     */
    public static boolean verifyConnectionTicketNo(String ticketNo) {
        if (ticketNo == null) {
            return false;
        }
        String regEx = "[0-9]{3}-?[0-9]{10}-[0-9]{1,2}";

        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(ticketNo);

        return m.matches();
    }

}
